package com.sprd.simple.launcher;

import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.sprd.simple.adapter.ToolsItemAdapter;
import com.sprd.simple.model.IconInfo;
import com.sprd.simple.util.AppIntentUtil;
import com.sprd.simple.util.FlashlightController;
import com.sprd.simple.util.KeyCodeEventUtil;
import com.sprd.simple.util.PackageInfoUtil;
import com.sprd.simple.util.StatusBarUtils;

import android.media.AudioManager;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;

//import com.sprd.android.support.featurebar.FeatureBarHelper;

/**
 * Created by SPDR on 2016/7/21.
 */
public class ToolsActivity extends BaseActivity<IconInfo> {
    private static final String TAG = "ToolsActivity";
    public static final String VOICE_MAIL_BROADCAST = "android.intent.action.VoiceMail";

    //private static final int ICON_SOS = 0;
    private static final int ICON_FIREWALL = 0;
    private static final int ICON_RECORDER = 1;
    private static final int ICON_NOTEBOOK = 2;
    private static final int ICON_BACKUP = 3;
    private static final int ICON_FILE = 4;
    private static final int ICON_CALCULATOR = 5;

    private ListView mToolsListView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tools);

        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,
                R.layout.tools_title_bar);

        mToolsListView = (ListView) findViewById(R.id.list_second_item);
        initListView(mToolsListView, new ToolsItemAdapter(this.getApplicationContext(), mInfos, appNameForTTS));
//        setSoftKey();
    }

    @Override
    protected List<IconInfo> loadData() {
        return getData();
    }

    private ArrayList<IconInfo> getData() {
        ArrayList<IconInfo> arrayList = new ArrayList<>();

        IconInfo fireWaller = new IconInfo();
        fireWaller.setIconName(getResources().getString(
                R.string.call_fire_wall_name));
        fireWaller.setIconImage(R.drawable.app_firewall);
        arrayList.add(fireWaller);

        IconInfo recorder = new IconInfo();
        recorder.setIconName(getResources().getString(
                R.string.sound_recorder_name));
        recorder.setIconImage(R.drawable.app_recorder);
        arrayList.add(recorder);

        IconInfo notebook = new IconInfo();
        notebook.setIconImage(R.drawable.app_notebook);
        notebook.setIconName(getResources().getString(R.string.note_name));
        arrayList.add(notebook);

        IconInfo backup = new IconInfo();
        backup.setIconName(getResources().getString(R.string.backup_name));
        backup.setIconImage(R.drawable.app_backup);
        arrayList.add(backup);

        IconInfo fileManager = new IconInfo();
        fileManager.setIconName(getResources().getString(
                R.string.file_manager_name));
        fileManager.setIconImage(R.drawable.app_filemanamger);
        arrayList.add(fileManager);

        IconInfo calculator = new IconInfo();
        calculator.setIconName(getResources().getString(
                R.string.calculator_name));
        calculator.setIconImage(R.drawable.app_caculator);
        arrayList.add(calculator);

       /* appNameForTTS = new String[] {
                getResources().getString(R.string.sos_name),
                getResources().getString(R.string.call_fire_wall_name),
                getResources().getString(R.string.note_name),
                getResources().getString(R.string.backup_name)};*/
        return arrayList;
    }

    @Override
    protected void launchApp(int flag) {
        Log.i(TAG, "launchApp flag = " + flag);
        Intent intent = new Intent();
        switch (flag) {
            case ICON_FIREWALL:
                intent.setClassName(
                        getResources().getString(
                                R.string.call_fire_wall_package),
                        getResources().getString(
                                R.string.call_fire_wall_activity));
                break;

            case ICON_RECORDER:
                intent.setClassName(
                        getResources().getString(
                                R.string.sound_recorder_package),
                        getResources().getString(
                                R.string.sound_recorder_activity));
                break;

            case ICON_NOTEBOOK:
                intent.setClassName(
                        getResources().getString(R.string.note_package),
                        getResources().getString(R.string.note_activity));
                break;

            case ICON_BACKUP:
                intent.setClassName(
                        getResources().getString(R.string.backup_package),
                        getResources().getString(R.string.backup_activity));
                break;

            case ICON_FILE:
                intent.setClassName(
                        getResources().getString(R.string.file_manager_package),
                        getResources()
                                .getString(R.string.file_manager_activity));
                break;
            case ICON_CALCULATOR:
                intent.setClassName(
                        getResources().getString(R.string.calculator_package),
                        getResources().getString(R.string.calculator_activity));
                break;

        }
        try {
            AppIntentUtil.intentSetFlag(intent);
            startActivity(intent);
        } catch (ActivityNotFoundException e) {
            Log.i(TAG, "App not found");
            Toast.makeText(this, R.string.app_not_found, Toast.LENGTH_LONG)
                    .show();
        }
    }

}
